package com.android.image;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.graphics.Bitmap;
import android.os.Handler;

import com.android.image.BitmapUtils.ScalingLogic;

/**
 * 
 */
public class AppUtils {

	private static final String TAG = "AppUtils";
	private static String DEVICE_ID = null;// 设备唯一标识
	private Handler handler;
	public static final int isEverytime_Tip = 1;
	public static final int isOnlyonce_Tip = 2;
	public static final int isNotforever_Tip = 3;

	public static int getVersionCode(Context ctx) {
		try {
			PackageInfo packInfo = ctx.getPackageManager().getPackageInfo(
					ctx.getPackageName(), 0);
			return packInfo.versionCode;
		} catch (Throwable t) {
			throw new RuntimeException(t);
		}
	}

	public static String getVersionName(Context ctx) {
		try {
			PackageInfo packInfo = ctx.getPackageManager().getPackageInfo(
					ctx.getPackageName(), 0);
			return packInfo.versionName;
		} catch (Throwable t) {
			throw new RuntimeException(t);
		}
	}

	public static int dipToPx(int dipValue) {
		final float scale = VGongyiApp.mDisplayScale;
		int pxValue = (int) (dipValue * scale + 0.5f);
		return pxValue;
	}
	
	public static int dipToPx(Context context, int dipValue) {
	    final float scale = context.getResources().getDisplayMetrics().density;
	    int pxValue = (int) (dipValue * scale + 0.5f);
	    return pxValue;
	}

	public static int pxToDip(Context context, float pxValue) {
		final float scale = context.getResources().getDisplayMetrics().density;
		return (int) (pxValue / scale + 0.5f);
	}

	public static String getOSVersionInfo() {
		/*
		 * return "device: "+android.os.Build.DEVICE + ",product:" +
		 * android.os.Build.PRODUCT + ",manufacturer: " +
		 * android.os.Build.MANUFACTURER + ",model: " + android.os.Build.MODEL;
		 */
		// return android.os.Build.VERSION.SDK+"-"+android.os.Build.MANUFACTURER
		// + "-"+ android.os.Build.PRODUCT + ("".equals(CUSTOM_TAG) ? "" : "-" +
		// CUSTOM_TAG);
		return android.os.Build.VERSION.RELEASE;
	}

	public static Bitmap getResizeBitmap(Bitmap unscaledBitmap, int width,
			int height) {
		// TODO Auto-generated method stub
		/** mDstWidth Wanted width of decoded image */
		/** mDstHeight Wanted height of decoded image */
		/** mSourceId Id of image resource to decode */
		// Part 1: Decode image
		// Part 2: Scale image
		Bitmap scaledBitmap = BitmapUtils.createScaledBitmap(unscaledBitmap,
				width, height, ScalingLogic.CROP);
		if (unscaledBitmap != null && !unscaledBitmap.isRecycled()) {
			unscaledBitmap.recycle();
			unscaledBitmap = null;
		}
		return scaledBitmap;
	}
}
